/*
 * OpenParts
 * A dynamic-loading components framework for GWT
 * Copyright (C) 2011 Christophe Bouthier  [chris{AT}binary-gastronome{DOT}fr]
 *
 * This work is partially based on work I have done at INRIA (http://www.inria.fr) 
 * in the context of the Qualipso European Project (http://qualipso.org/),
 * The work done at INRIA is Copyright (C) 2006-2011 INRIA
 *
 * This work is distributed under the LGPL version 3
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation. See the GNU
 * Lesser General Public License in LGPL.txt for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package fr.openparts.opshowcase.widgetcontainer.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.Widget;

import fr.openparts.opshowcase.widgetcontainer.client.presenter.WidgetContainerPresenter;
import fr.openparts.opshowcase.widgetcontainer.client.resources.WidgetContainerResources;

/**
 * View of a Widget Container for OpenParts Showcase.
 * 
 * @author Christophe Bouthier [chris{AT}binary-gastronome{DOT}fr]
 * @creation.date 06 May 2011
 */
public class WidgetContainerView extends Composite {

    interface WidgetContainerViewUiBinder extends UiBinder<Widget, WidgetContainerView> {}
    private static WidgetContainerViewUiBinder uiBinder = GWT.create(WidgetContainerViewUiBinder.class);

    protected WidgetContainerPresenter presenter;

    @UiField
    protected WidgetContainerResources resources;
    
    @UiField
    protected Button setStyleName;
    @UiField
    protected Button addStyleName;
    @UiField
    protected Button removeStyleName;
    @UiField
    protected Button setStylePrimaryName;
    @UiField
    protected Button addStyleDependentName;
    @UiField
    protected Button removeStyleDependentName;
    @UiField
    protected Button setWidth;
    @UiField
    protected Button setHeight;
    @UiField
    protected Button setSize;
    @UiField
    protected Button setVisible;
    
    @UiField
    protected LayoutPanel content;
    
    protected boolean visible = false;
    
    /**
     * Constructor.
     */
    public WidgetContainerView(final WidgetContainerPresenter presenter) {
        initWidget(uiBinder.createAndBindUi(this));
        resources.style().ensureInjected();
        this.presenter = presenter;
        presenter.displayEmbeddedView(this);
    }
    
    /**
     * Set the content of this view.
     */
    public void setContent(final Widget view) {
        content.add(view);
    }
    
    // buttons handlers. Call the corresponding methods on the presenter
    
    @UiHandler("setStyleName")
    public void onSetStyleName(final ClickEvent event) {
        presenter.setStyleName();
    }
    
    @UiHandler("addStyleName")
    public void onAddStyleName(final ClickEvent event) {
        presenter.addStyleName();
    }
    
    @UiHandler("removeStyleName")
    public void onRemoveStyleName(final ClickEvent event) {
        presenter.removeStyleName();
    }
    
    @UiHandler("setStylePrimaryName")
    public void onSetStylePrimaryName(final ClickEvent event) {
        presenter.setStylePrimaryName();
    }
    
    @UiHandler("addStyleDependentName")
    public void onAddStyleDependentName(final ClickEvent event) {
        presenter.addStyleDependentName();
    }
    
    @UiHandler("removeStyleDependentName")
    public void onremoveStyleDependentName(final ClickEvent event) {
        presenter.removeStyleDependentName();
    }
    
    @UiHandler("setWidth")
    public void onSetWidth(final ClickEvent event) {
        presenter.setWidth();
    }
    
    @UiHandler("setHeight")
    public void onSetHeight(final ClickEvent event) {
        presenter.setHeight();
    }
    
    @UiHandler("setSize")
    public void onSetSize(final ClickEvent event) {
        presenter.setSize();
    }
    
    @UiHandler("setVisible")
    public void onSetVisible(final ClickEvent event) {
        presenter.setVisible(visible);
        visible = !visible;
    }

}
